package com.txy.webmanagement.control;

import com.txy.webmanagement.model.SysProductType;
import com.txy.webmanagement.service.SysProductTypeService;
import com.txy.webmanagement.utils.RequestDataUtils;
import com.txy.webmanagement.utils.SysParrentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 产品类型操作管理
 *
 * @author wf
 * @date 2019-03-03$
 **/
@Controller
@RequestMapping(value = "productType")
public class SysProductTypeControl {
    @Autowired
    private SysProductTypeService sysProductTypeService;

    @RequestMapping(value = "index")
    public String index() {

        return "product/type/index";
    }

    @RequestMapping(value = "gotoSave")
    public String gotoSave() {

        return "product/type/add";
    }

    @RequestMapping(value = "ajaxProductType")
    @ResponseBody
    public RequestDataUtils ajaxProductType(SysProductType type) {
        RequestDataUtils req = new RequestDataUtils();
        List<SysProductType> li = sysProductTypeService.pageList(type);
        req.setData(li);
        return req;
    }

    @RequestMapping(value = "add")
    @ResponseBody
    public RequestDataUtils add(SysProductType type) {
        RequestDataUtils req = new RequestDataUtils();
        Boolean boo = sysProductTypeService.save(type);
        if (boo) {
            req.setCode(SysParrentUtils.successCode);
            req.setMessage(SysParrentUtils.successMsg);
        } else {
            req.setCode(SysParrentUtils.errorCode);
            req.setMessage(SysParrentUtils.addErrorMsg);
        }
        return req;
    }

    @RequestMapping(value = "delete")
    @ResponseBody
    public RequestDataUtils delete(String uuid) {
        RequestDataUtils req = new RequestDataUtils();
        sysProductTypeService.delete(uuid);
        return req;
    }
}
